package
{
	import com.darwin.darwinDll.Dll;
	import com.darwin.darwinDll.event.DllEvent;
	import com.darwin.darwinUI.manager.UIStage;
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.system.Security;
	
	import main.App;
	import main.AppConfig;

	[SWF(width="798",height="600",backgroundColor="#000000")]
	/**
	 * 主程序类 
	 * @author lipi 
	 */
	public class entry extends Sprite
	{
		public function entry()
		{
			super();
			if(stage) 
			{
				init();
			}
			else
			{
				stage.addEventListener(Event.RESIZE,onResize);
			}
		}
		
		/**
		 * 添加到舞台检测 
		 */
		private function onResize(e:Event):void
		{
			if(stage.stageWidth > 0 && stage.stageHeight>0)
			{
				stage.removeEventListener(Event.RESIZE,onResize);
				init();
			}
			
			init();
		}
		
		private var mainLayer:Sprite;
		private var loadingLayer:Sprite;//loading所在层
		private var loadingSprite:DisplayObject;
		
		private var $platformIniUrl:String = "files/";
		private var $platformOutUrl:String = "";
		private var $platformEntryUrl:String = "";
		
		
		private function init():void{
			AppConfig.getInstance().platFormObj = this.stage.loaderInfo.parameters;
			
			mainLayer = new Sprite();
			addChild(mainLayer);
			
			loadingLayer = new Sprite();
			addChild(loadingLayer);
			
			Security.allowDomain("*");
			Security.allowInsecureDomain("*");
			
			Dll.getInstance().lang = AppConfig.getInstance().lang;
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.tabChildren = false;
			stage.frameRate = 30;
			App.appStage = stage;
			UIStage.uiStage = stage;

			
			Dll.getInstance().addEventListener(DllEvent.MAIN_COMPLETE,mainCompHandler);
			Dll.getInstance().addEventListener(DllEvent.CONFIG_COMPLETE,configCompHandler);
			Dll.getInstance().outFolderUrl = AppConfig.getInstance().folder + "outresource_" + AppConfig.getInstance().lang + "/";
			Dll.getInstance().setInitConfig(["ini.xml","outini.xml"]);
			
			
			
		}
		private function mainCompHandler(e:DllEvent):void
		{
			var loader:Loader = Dll.getInstance().getSynPreloadRes("main") as Loader;
			mainLayer.addChild(loader);

		}
		private function configCompHandler(e:DllEvent):void
		{
			Dll.getInstance().loadMainMoudle();
		}
	}
}